<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>账号信息</title>
<link href="/djzx/css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/djzx/js/jquery-1.8.1.min.js"></script>
<script language="javascript" type="text/javascript" src="/djzx/js/My97DatePicker/WdatePicker.js"></script>
<script language="JavaScript" type="text/javascript" src="/djzx/js/backPage/clientSideApp.js"></script>
<script language="javascript">

function goback(){
	window.location.href="/djzx/AdminAction!getAdminListForPage.action";
}

function updateAdmin(){
	var name = $.trim($('#name').val());
	var password = $.trim($('#password').val());
	var confirmPassword = $.trim($('#confirmPassword').val());
	var role = $.trim($('#role').val());
	
	if(name == ""){
		alert("用户名不能为空");
		return;
	}
	if(password == ""){
		alert("密码不能为空");
		return;
	}
	if(password.length < 6){
		alert("密码的长度至少6位");
		return;
	}
	if(confirmPassword == ""){
		alert("确认密码不能为空");
		return;
	}
	if(password != confirmPassword){
		alert("两次输入的密码不一致");
		return;
	}
	var timeKey = $.trim($('#timeKey').val());
	var fd = new FormData();
	fd.append('admin.timeKey',timeKey);
	fd.append('admin.name',name);
	fd.append('admin.password',password);
	fd.append('admin.role.timeKey',role);
	
	$.ajax({
	    url:"${pageContext.request.contextPath}/AdminAction!updateAdmin.action",
	    type:"POST",
	    data:fd,
	    dataType: "json", 
	    contentType: false, //必须
	    processData: false, //必须
	    success:function(data){
	    	alert(data.message);
			if(data.success){
				window.location.href="/djzx/AdminAction!getAdminListForPage.action";
			}
	    }
	}); 
}

$(document).ready(function(){
	// 初始化角色信息
	$('#role').val('${admin.role.timeKey }');
});

</script>
<style type="text/css">
select{
	width: 243px;
}
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="25" align="center" valign="bottom" class="td06"><table width="98%" border="0" cellspacing="3" cellpadding="0">
      <tr>
        <td width="15"><img src="/djzx/images/index_32.gif" width="9" height="9"></td>
        <td valign="bottom" class="title">编辑角色</td>
      </tr>
    </table></td>
  </tr>
</table>
<br>
<input type="hidden" name="timeKey" id="timeKey" value="${admin.timeKey }" />
<table align="center" width="95%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
        <td width="120" height="24" class="td_form01">用户名</td>
        <td nowrap class=td_form02>
        	<input type="text" name="name" id="name" size="30" value="${admin.name }" />
        </td>
      </tr>
      <tr>
        <td width="120" class="td_form01">密码</td>
        <td nowrap class=td_form02 colspan="3">
        	<input type="password" name="password" id="password" size="30" />
		</td>
      </tr>
      <tr>
        <td width="120" class="td_form01">确认密码</td>
        <td nowrap class=td_form02 colspan="3">
        	<input type="password" name="confirmPassword" id="confirmPassword" size="30" />
		</td>
      </tr>
      <tr>
        <td width="120" class="td_form01">角色</td>
        <td nowrap class=td_form02 colspan="3">
        	<select id="role">
        		<s:iterator value="roleList" var="r" status="statu">
        		<option value="${r.timeKey }">${r.name }</option>
        		</s:iterator>
        	</select>
		</td>
      </tr>
</table>
<br>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center"><input name="Submit2" type="button" class="buttonface" value="  保存  " onClick="updateAdmin()">
    <input name="Submit" type="button" class="buttonface" value="  返回  "  onClick="goback()"></td>
  </tr>
</table>
<br>
</body>
</html>